<template>
	<view class="u-page">
		<view class="home_header">
			<view class="bg_1">
				<view class="time_select flex flex-align ">
					<view class="flex-1" @click="getTime(1)">
						<view class="icon left">
							<u-icon name="play-left-fill" color="#98999b" size="16"></u-icon>
						</view>
						<view class="left line flex flex-align flex-center">{{start}}</view>
					</view>
					<view class="flex-1" @click="getTime(2)">
						<view class="right flex flex-align flex-center">{{end}}</view>
						<view class="icon right">
							<u-icon name="play-right-fill" color="#98999b" size="16"></u-icon>
						</view>
					</view>
				</view>
				<view class="center">成交金额</view>
				<view class="center bold font30">
					<u-count-to color="#333" fontSize="30" decimals="2" :start-val="0" :end-val="dataInfo.sum" :duration="2000" :useEasing="false"></u-count-to>
				</view>
			</view>
			<u-datetime-picker @confirm="confirm" @cancel="cancel" @close="close" :show="show"  v-model="value" mode="datetime" ></u-datetime-picker>
		</view>
		<view class="bg_2">
			<view class="zhang_list flex-line">
				<view class="list" v-for="(item,index) in dataList" :key="index">
					<view class="flex flex-align flex-center">
						 <u-image mode="aspectFit" width="40rpx" height="40rpx" :src="item.logo" />
						 <view class="wenzi">{{item.name}}</view>
					</view>
					<view class="bold">
						￥<u-count-to color="#333" decimals="2" fontSize="26" :start-val="0" :end-val="item.sum" :duration="2000" :useEasing="false"></u-count-to>
					</view>
				</view>
			</view>
		</view>
		<!-- 清春 /快多来-->
		<view class="gongju">
			<view class="title">常用工具</view>
			<view class="gongju_list flex-line">
				<view class="list" v-for="(item,index) in daohangList" :key="index" @click="goUrl(item.url)">
					<view class="flex flex-center">
						<u-image mode="aspectFit" width="60rpx" height="60rpx" :src="item.logo" />
					</view>
					<view class="">{{item.name}}</view>
				</view>
			</view>
		</view>
		
	</view>
</template>

<script>
	export default {
		data() {
			return {
				title: 'Hello',
				show:false,
				value:'2024-07-12 00:00',
				show1:false,
				type:'',
				start:'',
				end:'',
				dataInfo:'',
				dataList:[],
				daohangList:[]
			}
		},
		async onLoad(e) {
			
			this.tui.getRoomSwitch(e.type)
			if(!uni.getStorageSync('configInfo')){
				uni.clearStorage()
				uni.redirectTo({
					url: '/pages/login/login'
				})
			}
			if(e.type&&e.type!==uni.getStorageSync('configInfo').item.identification){
				uni.clearStorage()
				uni.redirectTo({
					url: '/pages/login/login'
				})
			}
			const today = new Date();
			const year = today.getFullYear();
			const month = String(today.getMonth() + 1).padStart(2, '0');
			const day = String(today.getDate()).padStart(2, '0');
			this.start = year + '-' + month + '-' + day +" 00:00"
			this.end = year + '-' + month + '-' + day +" 24:00"
			this.value = year + '-' + month + '-' + day +" 00:00"
			this.getData()
			this.getDaohang()
			this.tui.wxShare()
		},
		methods: {
			getTime(e){
				
				this.type = e
				this.show = true
			},
			dateToTimestamp(date) {
			  return Math.floor(date.getTime());
			},
			goUrl(e){
				this.tui.href(e)
			},
			close() {
				this.show = false
			},
			cancel() {
				this.show = false
			},
			confirm(e) {
				this.show = false
				console.log(e)
				this.result(e.value, e.mode)
			},
			result(time, mode,e) {
				const timeFormat = uni.$u.timeFormat
				if(this.type==1){
					this.start = timeFormat(time, 'yyyy-mm-dd hh:MM')
				}else{
					this.end = timeFormat(time, 'yyyy-mm-dd hh:MM')
				}
				const time1 = new Date(this.start).getTime();
				const time2 = new Date(this.end).getTime();
				if(time1<time2){
					this.getData()
				}
			},
			getData(){
				let that = this
				that.tui.request("auth.info/sumInfo", "POST", {start_time:that.start,end_time:that.end}, false, false, true).then((res) => {
					if(res.code==1){
						that.dataInfo = res.data
						that.dataList = res.data.list
					}
				}).catch((res) => {
					
				})
			},
			getDaohang(){
				let that = this
				that.tui.request("auth.info/entrance", "POST", {}, false, false, true).then((res) => {
					if(res.code==1){
						that.daohangList = res.data.list
					}
				}).catch((res) => {
					
				})
			},
		}
	}
</script>

<style lang="scss">
	page{background: #f2f2f2;padding-bottom: 20rpx;}
	 .home_header{background:linear-gradient(to bottom,#0cb06b,#2dbb81 50%,#dfeee9);height: 400rpx;padding-top: 30rpx;
		.bg_1{background: #f6f5fa;margin:0 50rpx 30rpx;padding: 30rpx 30rpx 60rpx;border-radius: 20rpx;}
		.time_select{background: #e1e7fd;border-radius: 80rpx;padding: 0rpx 30rpx;margin-bottom: 30rpx;height: 70rpx;
			.flex-1{position: relative;
				.icon.left{position: absolute;left: -20rpx;top: 2rpx;}
				.icon.right{right: -20rpx;position: absolute;top: 2rpx;}
			}
			.line{border-right: 3px solid #ccd4fb;}
			view{height: 100%;text-align: center;font-size: 24rpx;color: #1ea779;font-weight: bold;}
		}
		.center{text-align: center;margin: 15rpx 0;}
	 }
	 .bg_2{background: #fff;padding: 40rpx 0 20rpx;margin: -100rpx 30rpx 0;border-radius: 0 0 15rpx 15rpx;
		.list{width: 50%;text-align: center;padding: 20rpx 0;margin-bottom: 20rpx;
			.wenzi{margin-left: 10rpx;}
			.bold{margin-top: 20rpx;font-size:36rpx}
		}
	 }
	 .gongju{
		 .title{font-weight: bold;font-size: 34rpx;padding: 30rpx;}
		 .gongju_list{background: #fff;border-radius: 10rpx;padding: 40rpx 0 30rpx;margin:0 30rpx 30rpx;
			.list{width: 33.3%;text-align: center;margin-bottom: 30rpx;
				.flex{margin: 20rpx 0;}
			}
		 }
	 }
	.font30{font-size: 30px;}
</style>